Exercise - Loops

  • Create a program to count by prime numbers. Ask the user to input a number, then print each prime number up to that number.
  • Instruct the user to pick an arbitrary number from 1 to 100 and proceed to guess it correctly within seven tries. After each guess, the user must tell whether their number is higher than, lower than, or equal to your guess.
  • Print all the characters in sentance "The continue statement is used in a while or for loop"
  • Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, between 2000 and 3200 (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.
  • When does while loop in the following code exit?
    x=input('Enter a passkeyid: ')
    while x != str(10):
        print(x),
        x=input('Enter a passkeyid: ')
    key=raw_input("Press key...")
    
  • What would be printed from the following Python code segments?

    • for i in range(10,0,-3):
          print(i)
      
    • for x in range(1, 6):
        for y in range(1, x + 1):
            print(x, y)
      
    • x=10
      while x > 5:
         print(x),
         x-=1
      

In [ ]: